<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of glmfwd</title>
  <meta name="keywords" content="glmfwd">
  <meta name="description" content="GLMFWD	Forward propagation through generalized linear model.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; glmfwd.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>glmfwd
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>GLMFWD	Forward propagation through generalized linear model.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [y, a] = glmfwd(net, x) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">GLMFWD    Forward propagation through generalized linear model.

    Description
    Y = GLMFWD(NET, X) takes a generalized linear model data structure
    NET together with a matrix X of input vectors, and forward propagates
    the inputs through the network to generate a matrix Y of output
    vectors. Each row of X corresponds to one input vector and each row
    of Y corresponds to one output vector.

    [Y, A] = GLMFWD(NET, X) also returns a matrix A  giving the summed
    inputs to each output unit, where each row corresponds to one
    pattern.

    See also
    <a href="glm.html" class="code" title="function net = glm(nin, nout, outfunc, prior, beta)">GLM</a>, <a href="glmpak.html" class="code" title="function w = glmpak(net)">GLMPAK</a>, <a href="glmunpak.html" class="code" title="function net = glmunpak(net, w)">GLMUNPAK</a>, <a href="glmerr.html" class="code" title="function [e, edata, eprior, y, a, mse] = glmerr(net, x, t)">GLMERR</a>, <a href="glmgrad.html" class="code" title="function [g, gdata, gprior] = glmgrad(net, x, t)">GLMGRAD</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="consist.html" class="code" title="function errstring = consist(model, type, inputs, outputs)">consist</a>	CONSIST Check that arguments are consistent.</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="demglm1.html" class="code" title="">demglm1</a>	DEMGLM1 Demonstrate simple classification using a generalized linear model.</li><li><a href="demglm2.html" class="code" title="">demglm2</a>	DEMGLM2 Demonstrate simple classification using a generalized linear model.</li><li><a href="glmerr.html" class="code" title="function [e, edata, eprior, y, a, mse] = glmerr(net, x, t)">glmerr</a>	GLMERR Evaluate error function for generalized linear model.</li><li><a href="glmevfwd.html" class="code" title="function [y, extra, invhess] = glmevfwd(net, x, t, x_test, invhess)">glmevfwd</a>	GLMEVFWD Forward propagation with evidence for GLM</li><li><a href="glmgrad.html" class="code" title="function [g, gdata, gprior] = glmgrad(net, x, t)">glmgrad</a>	GLMGRAD Evaluate gradient of error function for generalized linear model.</li><li><a href="glmhess.html" class="code" title="function [h, hdata] = glmhess(net, x, t, hdata)">glmhess</a>	GLMHESS Evaluate the Hessian matrix for a generalised linear model.</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [y, a] = glmfwd(net, x)</a>
0002 <span class="comment">%GLMFWD    Forward propagation through generalized linear model.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%    Y = GLMFWD(NET, X) takes a generalized linear model data structure</span>
0006 <span class="comment">%    NET together with a matrix X of input vectors, and forward propagates</span>
0007 <span class="comment">%    the inputs through the network to generate a matrix Y of output</span>
0008 <span class="comment">%    vectors. Each row of X corresponds to one input vector and each row</span>
0009 <span class="comment">%    of Y corresponds to one output vector.</span>
0010 <span class="comment">%</span>
0011 <span class="comment">%    [Y, A] = GLMFWD(NET, X) also returns a matrix A  giving the summed</span>
0012 <span class="comment">%    inputs to each output unit, where each row corresponds to one</span>
0013 <span class="comment">%    pattern.</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%    See also</span>
0016 <span class="comment">%    GLM, GLMPAK, GLMUNPAK, GLMERR, GLMGRAD</span>
0017 <span class="comment">%</span>
0018 
0019 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0020 
0021 <span class="comment">% Check arguments for consistency</span>
0022 errstring = <a href="consist.html" class="code" title="function errstring = consist(model, type, inputs, outputs)">consist</a>(net, <span class="string">'glm'</span>, x);
0023 <span class="keyword">if</span> ~isempty(errstring);
0024   error(errstring);
0025 <span class="keyword">end</span>
0026 
0027 ndata = size(x, 1);
0028 
0029 a = x*net.w1 + ones(ndata, 1)*net.b1;
0030 
0031 <span class="keyword">switch</span> net.outfn
0032 
0033   <span class="keyword">case</span> <span class="string">'linear'</span>     <span class="comment">% Linear outputs</span>
0034     y = a;
0035 
0036   <span class="keyword">case</span> <span class="string">'logistic'</span>   <span class="comment">% Logistic outputs</span>
0037     <span class="comment">% Prevent overflow and underflow: use same bounds as glmerr</span>
0038     <span class="comment">% Ensure that log(1-y) is computable: need exp(a) &gt; eps</span>
0039     maxcut = -log(eps);
0040     <span class="comment">% Ensure that log(y) is computable</span>
0041     mincut = -log(1/realmin - 1);
0042     a = min(a, maxcut);
0043     a = max(a, mincut);
0044     y = 1./(1 + exp(-a));
0045 
0046   <span class="keyword">case</span> <span class="string">'softmax'</span>       <span class="comment">% Softmax outputs</span>
0047     nout = size(a,2);
0048     <span class="comment">% Prevent overflow and underflow: use same bounds as glmerr</span>
0049     <span class="comment">% Ensure that sum(exp(a), 2) does not overflow</span>
0050     maxcut = log(realmax) - log(nout);
0051     <span class="comment">% Ensure that exp(a) &gt; 0</span>
0052     mincut = log(realmin);
0053     a = min(a, maxcut);
0054     a = max(a, mincut);
0055     temp = exp(a);
0056     y = temp./(sum(temp, 2)*ones(1,nout));
0057     <span class="comment">% Ensure that log(y) is computable</span>
0058     y(y&lt;realmin) = realmin;
0059 
0060   <span class="keyword">otherwise</span>
0061     error([<span class="string">'Unknown activation function '</span>, net.outfn]);
0062 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>